package org.opu.pc.ui.client.widgets;

import java.util.Collection;
import java.util.Date;

import org.opu.pc.services.beans.AbstractBean;
import org.opu.pc.services.beans.PublicationBean;
import org.opu.pc.ui.client.BeanView;
import org.opu.pc.ui.client.i18n.PublicationI18N;

public class TableRenderPublication implements TableRender<PublicationBean> {

    public static final Class<?>[] TYPES = new Class<?>[]{
        String.class,
        String.class,
        Date.class,
        String.class,
        Integer.class,
        Integer.class,
        Boolean.class
    };
	public static final Object[] COLUMN_NAMES;

	static {
        PublicationI18N i18n = new PublicationI18N();
        COLUMN_NAMES = new Object[]{
                    i18n.get("name", "Name"),
                    i18n.get("publication.place", "Publication place"),
                    i18n.get("date", "Date"),
                    i18n.get("conference.venue", "Conference venue"),
                    i18n.get("page.start.number", "First page"),
                    i18n.get("page.end.number", "Last page"),
                    i18n.get("publication.applied", "Applied by HAC")
        };
	}

	@Override
	public Class<PublicationBean> getRenderingClass() {
		return PublicationBean.class;
	}

	@Override
	public void rendView(Collection<? extends AbstractBean> beans, BeanView view) {
		Object[][] rowData = new Object[beans.size()][TYPES.length];

		int i = 0;
		for (AbstractBean tb : beans) {
			PublicationBean bean = (PublicationBean) tb;
			rowData[i][0] = bean.getName();
            rowData[i][1] = bean.getPublicationPlace();
            rowData[i][2] = bean.getDate();
            rowData[i][3] = bean.getConferenceVenue();
            rowData[i][4] = bean.getPageNumberStart();
            rowData[i][5] = bean.getPageNumberEnd();
			rowData[i][6] = bean.isWasApplied();
			i++;
		}
		view.setContent(COLUMN_NAMES, TYPES, rowData);
	}

}
